﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPAIS.Updater
{
    /// <summary>
    /// Represents an abstract updater for updating status information.
    /// </summary>
    /// <exception cref="CancelUpdatingException">Thrown when cancelling updating</exception>
    public abstract class StateUpdater : Updater
    {
        /// <summary>
        /// Updates progress message.
        /// </summary>
        /// <param name="message">Message for progressing</param>
        /// <exception cref="CancelUpdatingException">Thrown when cancelling updating</exception>
        public void UpdateMessage(string message)
        {
            if (State == UpdateState.Updating)
            {
                this.message = message;
                if (!OnUpdateMessage(message))
                {
                    Cancel();
                }
            }
        }
        protected abstract bool OnUpdateMessage(string message);
    }
}
